<template>
  <div>
    <BreakSpace label="旧件不回运" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel" :list="formList" labelWidth="110" :formType="type" @formChange="changeHandle" :isSubmitBtn="false" />
    <div>
      <BreakSpace label="审核说明" :containerStyle="{ marginBottom: '10px' }" />
      <FormPanel :cols="3" :list="form" :formType="type" :isSubmitBtn="false" ref="examineinfoChanges" columnsRef="notification_maintain_index_02" :onColumnsChange="(columns) => (this.columns = columns)" />
    </div>
    <div>
      <BreakSpace label="审核操作历史" :containerStyle="{ marginBottom: '10px' }" />
      <FilterTable
        ref="zctable"
        :columns="czcolumns"
        :params="fetchParams"
        :datakey="'records'"
        :isSelectColumn="false"
        columnsRef="notification_maintain_index_03"
        :onColumnsChange="(columns) => (this.czcolumns = columns)"
      >
      </FilterTable>
    </div>
    <div class="dialogBottmView">
      <!-- <el-button size="small" type="primary" class="btnStyle" @click="saveHandler">保存 </el-button> -->
      <el-button size="small" type="primary" v-if="isDetailed" class="btnStyle" @click="examine(true)">同意报废 </el-button>
      <el-button size="small" type="primary" v-if="isDetailed" class="btnStyle" @click="examine(false)">审核驳回 </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeMenu('3')">返回 </el-button>
    </div>
     <Drawer :visible.sync="visibleEdit" :title="'索赔单明细'" destroyOnClose width="100%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <editForm @close="editclose" @save="editsave" :rowData="rowData"></editForm>
    </Drawer>
  </div>
</template>

<script>
import editForm from '@/pages/claimDemage/BasicData/ClaimQueryFactory/editForm.vue';
import { dealerMixin } from '@/pages/repair/batchEventManagement/dealerMixin';
import { dictionary } from '@/utils/dictMixin';
import config from '@/assets/js/config';
import { examineScrap} from '@/api/repair/usedScrap/usedScrapAudit';

export default {
  name: 'audit',
  mixins: [dictionary, dealerMixin],
  /*handleType show   活动审核  show-1  索赔审核*/
  props:{
    row: {
      type: Object,
      required: true
    },
    type: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      uploadPrefix: config.uploadUrl,
      appendixName: '',
      czcolumns: this.createCzTableColumns(),
      formList: this.createFormList(),
      form: this.createForm(),
      visibleVin: false,
      visibleSport: false,
      visiblePeij: false,
      visibleMainCode: false,
      visibleEdit:false,
      fetchParams: { xhrAbort: true },
      fetchParamPeij: { xhrAbort: true },
      fetchParamSport: { xhrAbort: true },
      fetchParamSuopei: { xhrAbort: true },
      fetchApiPeij: '',
      fetchApi: '',
      optRemark: '',
      fetchApiSuopei: '',
      fetchParamsVin: { xhrAbort: true },
      onChangeColumn: [],
      vinArr: [] /**/,
      sportArr: [],
      peijArr: [],
      fujArr: [],
      status: 1 /*1  表单选择  2 新建配件*/,
      detailObj: {},
      imageList: [],
      UploadFileIsShow: false,
      saveData: null,
      nrNumAll:0,
      nrNum:0,
      nrId:0,
      checkOpinion: '',
      whName: null,
      whCode: null,
      dataList: [],
      fileList :[],
      rowData: {},
      isDetailed:true,

    };
  },
  components: {editForm},
  mounted() {

      this.formList.forEach(t => {
        t.initialValue = this.row[t.fieldName];
      });
     this.isDetailed = this.type == 'detail'?false:true;

    this.$refs.zctable.$refs.pageTable.EXECUTE_INSERT(this.row.log);

  },
   async created(){

  },
  methods: {

     async examine(isExamine){
      if(isExamine == true){
         let [err1, data1] = await this.$refs.examineinfoChanges.GET_FORM_DATA();
             data1 = Object.assign({},this.row,data1,
            {state: 55711003,
              checkOpinion:data1.checkOpinion,
            })
          console.log('data1', data1);
          let res = await examineScrap(data1);
          if (res.resultCode == 200) {
            this.$notify.success({ title: '提示信息', message: '操作成功!' });
              this.$emit('close', 'refresh');
          }
          this.$emit('close', 'refresh');
          return;
      }else{
        if(isExamine == false && this.form.find(x => x.fieldName === 'checkOpinion').initialValue === ''){
            this.$notify.error({ title: '提示信息', message: '审核驳回时请填写审核说明!' });
        }else{
            let [err1, data1] = await this.$refs.examineinfoChanges.GET_FORM_DATA();
             data1 = Object.assign({},this.row,data1,
            {state: 55711004,
              checkOpinion:data1.checkOpinion,
            })
          console.log('data1', data1);
          let res = await examineScrap(data1);
          if (res.resultCode == 200) {
            this.$notify.success({ title: '提示信息', message: '操作成功!' });
              this.$emit('close', 'refresh');
          }

        }
      }


      },
    cheageselect(data) {
      console.log(data);
      this.txt.data;
    },
     changeHandle(val){
      console.log('changeHandle', val);
      this.saveData = val;
    },

    claimDetail() {
      this.visibleEdit = true;
    },

    editclose() {
      this.visibleEdit = false;
    },
    editsave() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
    async closeMenu(type) {
      this.$emit('close');
    },
    closeDialog() {
      this.visibleVin = false;
    },

    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '报废单号',
          fieldName: 'scrapNo',
          itemList: [],
          disabled: true,
          width: 110,
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '服务中心代码',
          fieldName: 'dealerCode',
          width: 150,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '服务中心简称',
          fieldName: 'dealerName',
          disabled: true,
          initialValue: '',
        },


        {
          type: 'INPUT',
          label: '报废申请人',
          fieldName: 'complainBy',
          placeholder: '请选择',
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '报废申请人电话',
          fieldName: 'complainMobile',
          placeholder: '请输入',
          disabled: true,
          initialValue: '',
        },
        { type: 'SELECT', label: '报废类型', fieldName: 'scrapType', placeholder: '请选择', initialValue: '', disabled: true,
           itemList: this.createDictList(5570)
        },

        { type: 'INPUT',
          label: '绑定单号',
          fieldName: 'bindingNo',
          placeholder: '请选择',
          initialValue: '',
          readonly:true,
          disabled: true,
          rules: [{ required: true, message: '必填', trigger: 'blur' }],
          unitRender: p => {
              return (

                   <div>
                    <multiuse-button icon="el-icon-document" onClick={() => this.claimDetail()}/>
                  </div>
              );
          },
        },
        { type: 'INPUT', label: '旧件代码', fieldName: 'partCode', placeholder: '请选择', initialValue: '', disabled: true },
        { type: 'INPUT', label: '旧件名称', fieldName: 'partName', placeholder: '请选择', initialValue: '', disabled: true },
        { type: 'INPUT', label: '责任商代码', fieldName: 'supCode', placeholder: '请选择', initialValue: '', disabled: true },
        { type: 'INPUT', label: '责任商名称', fieldName: 'supName', placeholder: '请选择', initialValue: '', disabled: true },
        { type: 'INPUT', label: '不返件数量', fieldName: 'nrNum', placeholder: '请选择', initialValue: '', disabled: true },
        { type: 'INPUT', label: '报废数量', fieldName: 'scrapNum', placeholder: '请选择', initialValue: '', disabled: true },
        {
          type: 'TEXT_AREA',
          label: '报废原因说明',
          fieldName: 'complainReason',
          placeholder: '请选择',
          disabled: true,
          rules: [{ required: false, trigger: 'blur' },{ maxlength: 300, message: '长度最大300字符', trigger: 'blur' },],
          initialValue: '',
          maxlength:300,
          selfCols: 3,
        },

        {
          type: 'UPLOAD_FILE',
          label: '附件',
          disabled: true,
          fieldName: 'file',
          disabled: true,
          initialValue: '',
          selfCols: 4,
        },
      ];
    },
   createForm() {
      return [
        {
          type: 'TEXT_AREA',
          label: '审核说明',
          fieldName: 'checkOpinion',
          placeholder: '请输入',
          disabled: this.type ==='detail'?true:false ,
          initialValue: this.type ==='detail'?this.row['checkOpinion']:'',
          selfCols: 3,
          rows: 5,
          maxlength: 300,
          rules: [
            { required: false, message: '必填', trigger: 'blur' },
            { maxlength: 300, message: '长度最大300字符', trigger: 'blur' },
          ],
        },
      ];
    },
    //审核操作列表
    createCzTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        { title: '操作人', dataIndex: 'checkBy', sorter: true},
        {
          title: '操作状态',
          dataIndex: 'status',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.status, '5571')}</span>;
          }
        },
        { title: '操作时间', dataIndex: 'checkAt',dateFormat: 'yyyy-MM-dd HH:mm:ss', sorter: true },
        { title: '操作说明', dataIndex: 'opinion', sorter: true}
      ];
    },
  },
};
</script>

<style scoped lang="less">
.bg1 {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
  padding-left: 0;
  padding-top: 15px;
  padding-bottom: 15px;
}

.bg2 {
  margin-top: 10px;
  margin-bottom: 10px;
}

.btn {
  text-align: center;
}

.btnStyle {
  margin-top: 10px;
}
</style>
